package com.sgai.dcac.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sgai.dcac.R;
import com.sgai.dcac.ui.common.BaseActivity;
import com.sgai.dcac.ui.widget.recyclerView.decoration.DividerGridItemDecoration;

import java.util.ArrayList;

public class MenuActivity extends BaseActivity {

    private RecyclerView recyclerView;

    private ArrayList<String> mDatas;
    private HomeAdapter mAdapter;

    @Override
    protected void findViewById() {
        recyclerView = (RecyclerView) findViewById(R.id.menu_recycler_view);
    }

    @Override
    protected void setUpView() {
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.setLayoutManager(new GridLayoutManager(this,4));
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4,StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setAdapter(mAdapter = new HomeAdapter());
        //添加分割线
//        recyclerView.addItemDecoration(new DividerItemDecoration(
//                this, DividerItemDecoration.VERTICAL_LIST));
        recyclerView.addItemDecoration(new DividerGridItemDecoration(this));

        initData();
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_menu;
    }

    public static void startThisActivity (Activity activity) {
        activity.startActivity(new Intent(activity,MenuActivity.class));
    }

    private void initData()
    {
        mDatas = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++)
        {
            mDatas.add("" + (char) i);
        }
    }

    class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder>
    {

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    MenuActivity.this).inflate(R.layout.item_menu, parent,
                    false));
            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position)
        {
            holder.tv.setText(mDatas.get(position));
        }

        @Override
        public int getItemCount()
        {
            return mDatas.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder
        {

            TextView tv;

            public MyViewHolder(View view)
            {
                super(view);
                tv = (TextView) view.findViewById(R.id.item_menu_label);
            }
        }
    }
}
